package com.fancy.social.controller;

import com.fancy.social.dto.PrivateMessageCreateDTO;
import com.fancy.social.service.PrivateMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/messages")
public class PrivateMessageController {

    @Autowired
    private PrivateMessageService privateMessageService;

    @PostMapping
    public ResponseEntity<Void> sendMessage(@RequestHeader("X-User-Id") Long senderId, @RequestBody PrivateMessageCreateDTO privateMessageCreateDTO) {
        privateMessageService.sendMessage(senderId, privateMessageCreateDTO);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/{messageId}/read")
    public ResponseEntity<Void> readMessage(@RequestHeader("X-User-Id") Long userId, @PathVariable Long messageId) {
        privateMessageService.readMessage(userId, messageId);
        return ResponseEntity.ok().build();
    }
}
